//package com.xk.ucs.controller;
//
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.json.JSONUtil;
//import com.xk.ucs.common.Result;
//import com.xk.ucs.service.AdminRemoteService;
//import com.xk.ucs.service.ShelfService;
//import com.xk.ucs.service.UcsService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import java.util.Map;
//
///**
// * @ClassName ShelfController
// * @Description TODO:
// * @Author zhouLiang
// * @Date 2024/9/6 16:48
// */
//@Api(tags = "货架服务")
//@RestController
//@RequestMapping("")
//@Slf4j
//public class ShelfController {
//
//    @Resource
//    private ShelfService shelfService;
//    @Resource
//    private UcsService ucsService;
//
//
//    @PostMapping("scanAll")
//    @ApiOperation(value = "扫描整个货道",notes = "扫描整个货道")
//    public Result<Boolean> scanAll(){
//        return Result.success(shelfService.scanAll());
//    }
//
//    @ApiOperation(value = "取货", notes = "下单成功后，调用此接口取货")
//    @GetMapping("/grab/{orderNo}")
//    public Result grabGoods(@PathVariable("orderNo") String orderNo){
//        return Result.success(shelfService.grabByOrderId(orderNo));
//    }
//    @ApiOperation(value = "获取柜子状态", notes = "0：初始化状态   1：停止状态   2：手动状态   4：自动状态    5：报警状态 字典表中维护")
//    @GetMapping("/getStatus")
//    public Result getBoxStatus(){
//        return Result.success(shelfService.getBoxStatus());
//    }
//    @ApiOperation(value = "检测柜子是否开门", notes = "true-已开门，false-未开门")
//    @GetMapping("/isDoorOpened")
//    public Result isDoorOpened(){
//        isLog.set(false);
//        if(GlobalSetting.getInstance().getBoxNo()==0){
//            return Result.success(false);
//        }
//        return Result.success(boxService.isDoorOpened());
//    }
//
//    @ApiOperation(value = "开灯关灯", notes = "点击开灯，定时")
//    @PostMapping("/lightOne")
//    public Result makeLightOne(@RequestBody LightControlMode lightControlMode){
//        boolean b = modbusHandler.writeLightControlMode(lightControlMode);
//        return Result.success(b);
//    }
//
//
//    @ApiOperation(value = "开灯关灯", notes = "点击开灯，定时")
//    @PostMapping("/lightOne")
//    public Result makeLightOne(@RequestBody LightControlMode lightControlMode){
//        boolean b = modbusHandler.writeLightControlMode(lightControlMode);
//        return Result.success(b);
//    }
//
//    @PostMapping("confirmGoodsIn")
//    @ApiOperation(value = "确认已放货", notes = "这是第三步，柜门会关闭")
//    public Result<Boolean> confirmGoodsIn(@Validated @RequestBody  AfterSaleConfirmDTO saleConfirmDTO ) {
//        try {
//            String sign = saleConfirmDTO.getSign();
//            if(StringUtils.isNotEmpty(SIGN)&&
//                    sign.equals(SIGN)){
//                boolean b = modbusHandler.endRefund();
//
//                if(b){
//                    return  new Result(true);
//                }
//                throw  ErrorEnum.AFTER_SALE_ERROR.exp();
//
//
//            }
//            log.error("未找到SIGN,直接调confirmGoodsIn");
//            throw  ErrorEnum.SYS_ERROR.exp();
//        } finally {
//            SIGN="";
//        }
//
//    }
//
//
//    @PostMapping("start")
//    @ApiOperation(value = "开始退货", notes = "第一步调出订单，并确定可退时，调用本接口，填完信息后，会打开柜门,返回的序列号下一步确认关门时用")
//    public Result<String> getOrderByTraceCode(@RequestBody  AfterSaleDTO afterSaleDTO ) {
//        OrderAfterSale orderAfterSale = BeanUtil.copyProperties(afterSaleDTO, OrderAfterSale.class);
//        orderAfterSale.setAfterSaleType(1);
//        orderAfterSale.setBoxNo(GlobalSetting.getInstance().getBoxNo());
//        String refundNo = CommonUtil.getNo();
//        orderAfterSale.setRefundNo(refundNo);
//        orderAfterSale.setRefundStatus("WAITED");
//        OrderDetail detail = getOrderDetail(afterSaleDTO.getTraceCode());
//        orderAfterSale.setAmount(detail.getUnitPrice());
//        orderAfterSale.setProductId(detail.getProductId());
//        orderAfterSale.setTraceCode(afterSaleDTO.getTraceCode());
//        int insert = orderAfterSaleMapper.insert(orderAfterSale);
//        if(insert>0){
//            SIGN= MD5.create().digestHex16(JSONUtil.toJsonStr(afterSaleDTO));
//            boolean b = modbusHandler.startRefund();
//            if(b){
//                return   new Result(SIGN);
//            }else{
//                log.warn("下位机写入失败，无法退货");
//            }
//
//        }
//        throw  ErrorEnum.SYS_ERROR.exp();
//
//    }
//    @GetMapping("byTraceCode/{traceCode}")
//    @ApiOperation(value = "退货traceCode获取订单", notes = "这是退货的第一个接口，大于7天订单不可退货已校验，")
//    public Result<OrderDetailWithTraceCodeDTO> getOrderByTraceCode(@Validated @PathVariable String traceCode ) {
//        if(StrUtil.isBlank(traceCode)){
//            throw ErrorEnum.PARAM_INVALID.expMsg("商品溯源码不能为空");
//        }
//        OrderDetail one = getOrderDetail(traceCode);
//        if(one==null){
//            throw ErrorEnum.AFTER_SALE_ORDER_NOT_EXIST.exp(traceCode);
//        }
//        Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
//                .select(Order::getOrderNo,Order::getPayTime)
//                .eq(Order::getId,one.getOrderId())
//                .eq(Order::getPayStatus,1)
//                .eq(Order::getOrderStatus,1));//非异常
//        if(order==null||order.getOrderNo()==null){
//            throw ErrorEnum.AFTER_SALE_ORDER_NOT_EXIST.exp();
//        }
//        checkAlreadyRefund(order.getOrderNo());
//        checkExpired(order);
//        Product product = goodsService.getById(one.getProductId());
//        OrderDetailWithTraceCodeDTO orderDetailWithTraceCodeDTO =new OrderDetailWithTraceCodeDTO();
//        orderDetailWithTraceCodeDTO.setAmount(one.getUnitPrice());
//        orderDetailWithTraceCodeDTO.setNameCn(product.getNameCn());
//        orderDetailWithTraceCodeDTO.setGoodsImageUrl(product.getGoodsImageUrl());
//        orderDetailWithTraceCodeDTO.setOrderNo(order.getOrderNo());
//        orderDetailWithTraceCodeDTO.setOrderTime(order.getPayTime());
//        orderDetailWithTraceCodeDTO.setTraceCode(traceCode);
//        return Result.success(orderDetailWithTraceCodeDTO);
//    }
//
//    @PostMapping("replenish")
//    @ApiOperation(value = "上货",notes = "上货")
//    public Result<Map<String,Object>> replenish(@RequestBody Map<String,Object> req){
//        return Result.success(ucsService.replenish(req));
//    }
//}
